package com.xyh.transaction.common;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum OrderPayType {
    ONLINE_PAYMENT("在线支付"),
    CASH_ON_DELIVERY("货到付款");

    private static final Map<String, OrderPayType> map = new HashMap<>();

    static {
        for (OrderPayType type : OrderPayType.values()) {
            map.put(type.getDetail(), type);
        }
    }

    private final String detail;

    OrderPayType(String detail) {
        this.detail = detail;
    }

    public static OrderPayType getByDetail(String detail) {
        OrderPayType payType = map.get(detail);
        if (payType == null) {
            // 处理未知的详情字符串，例如返回一个默认值或抛出异常
            throw new IllegalArgumentException("Unknown pay type: " + detail);
        }
        return payType;
    }
}
